package gui.edit.components;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import gui.edit.enums.E_EditParamsCheckBoxes;
import gui.edit.listeners.ListenerParamCheckBoxChange;
import gui.edit.listeners.ListenerHelpButton;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import tuio.components.ButtonTouch;
import tuio.components.CheckBoxTouch;

import controls.edit.ParamControl;

import data.visu.utils.ImageLoader;
import data.visu.utils.StringFormater;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class ParamsCheckBoxesPanel extends JPanel{


	/**
	 * 
	 */
	private static final long serialVersionUID = -3792799351209747603L;
	
	private static final Font fontCheckBox = new Font("SansSerif", Font.PLAIN, 9);

	private CheckBoxTouch checkBox;

	private E_EditParamsCheckBoxes editParam;

	private ButtonTouch buttonHelp;
	
	private ParamControl controler;

	public ParamsCheckBoxesPanel(CheckBoxTouch checkBox, ParamControl controler, E_EditParamsCheckBoxes editParam){
		this.checkBox=checkBox;
		this.editParam=editParam;
		this.setControler(controler);

		initComponents();

		setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.insets = new Insets(0, 0, 1, 0);
		c.gridx=0;
		c.gridy=0;
		c.weightx=0;
		add(this.checkBox, c);

		c.gridx+=1;
		add(buttonHelp,c);
	}

	private void initComponents(){

		String nameString = editParam.getName();
		nameString = StringFormater.formatString(nameString, 15);
		
		checkBox.setText(nameString);
		checkBox.setFont(fontCheckBox);
		checkBox.setSelected(false);
		checkBox.addActionListener(new ListenerParamCheckBoxChange(this));

		ImageIcon icon = ImageLoader.createImageIcon("help.PNG");
		buttonHelp = new ButtonTouch(icon);
		buttonHelp.setMargin(new Insets(0,0,0,0));
		buttonHelp.setPreferredSize(new Dimension(12,12));
		buttonHelp.addActionListener(new ListenerHelpButton(controler.getParamsControl().getDisplayDataList().getDataControl().getIhm(), editParam.getName(), editParam.getInfos(), editParam.getImageURL()));
	}

	public void setControler(ParamControl controler) {
		this.controler = controler;
	}

	public ParamControl getControler() {
		return controler;
	}
}
